<template>
    <div>
        <el-card class="box-card" shadow="never">
            <i class="el-icon-search"></i>
            <span>筛选搜索</span>
            <el-row :gutter="10" style="margin-top:15px;">
               <el-col :span='6'>
                  <el-input v-model="nickname">
                    <template slot="prepend">昵称</template>
                  </el-input>
               </el-col>
            </el-row>
            <el-row :gutter="20" class="yx_el_row">
                <el-col :span="4">
                    <el-button type="success" plain @click="search">筛选</el-button>
                    <el-button type="primary" plain @click="add">添加</el-button>
                </el-col>
            </el-row>
            <div class="yx_line"></div>
            <div style="margin-top:10px;">
              <i class="el-icon-tickets"></i>
              <span>数据列表</span>
            </div>
            <el-table class="yx_table" border :data="stafflist">
                <el-table-column type="index" label="序号" width="80">
                </el-table-column>
                <el-table-column prop="avatar_url" label="头像" width="180">
                    <template slot-scope="scope">
                          <el-avatar :size="50" :src="scope.row.avatar_url"></el-avatar>
                    </template>
                </el-table-column>
                <el-table-column prop="nickname" label="昵称" width="180">
                </el-table-column>
                <el-table-column prop="phone" label="手机号" width="200">
                </el-table-column>
                <el-table-column prop="enabled_name" label="状态" width="200">
                </el-table-column>
                <el-table-column prop="created_at" label="注册时间" width="200">
                </el-table-column>
                <el-table-column  label="操作">
                    <template slot-scope="scope">
                        <el-tooltip v-if="scope.row.enabled==1" class="item" effect="dark" content="禁用"  placement="bottom-start">
                            <el-button type="warning" icon="el-icon-close" @click="edit(scope.row.id,0)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip v-else class="item" effect="dark" content="启用"  placement="bottom-start">
                            <el-button type="success" icon="el-icon-check" @click="edit(scope.row.id,1)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="解除" placement="bottom-start">
                            <el-button type="danger" icon="el-icon-delete" @click="del(scope.row.id)" circle></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <el-dialog id="staff-dialog" title="理赔人员设置" :visible="showDialog" :show-close=false :destroy-on-close=true width="30%">
                    <el-row>
                       <el-col :span="12">
                          <el-input v-model="search_nickname">
                            <template slot="prepend">昵称</template>
                          </el-input>
                       </el-col>
                       <el-col :span="6" style="margin-left:15px;">
                           <el-button type="success" plain @click="searchStaff()">筛选</el-button>
                       </el-col>
                    </el-row>
                     <el-table class="yx_table" border :data="alluserlist" style="height:300px;overflow-y: scroll;">
                        </el-table-column>
                        <el-table-column prop="avatar_url" label="头像" width="100">
                            <template slot-scope="scope">
                                  <el-avatar :size="30" :src="scope.row.avatar_url"></el-avatar>
                            </template>
                        </el-table-column>
                        <el-table-column prop="nickname" label="昵称">
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-link type="primary" @click="setStaff(scope.row.id)">设为理赔人员</el-link>
                            </template>
                        </el-table-column>
                     </el-table>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="closeDialog">关闭</el-button>
                </div>
            </el-dialog>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>

        </el-card>
    </div>
</template>

<script>
    import { getStaffList,listAllUser,setStaff } from '@/api/staff.js';
    import Pagination from '@/components/Pagination.vue';
    export default {
        name: 'StaffList',
        components:{ Pagination },
        inject:['reload'],
        data() {
            return {
                stafflist:[],
                total_count:0,
                nickname:'',
                showDialog:false,
                button_name:'设置理赔人员',
                search_nickname:'',
                alluserlist:[]
            }
        },
        methods: {
            getList(current_page,page_size){
                this.$store.dispatch('loadCurrentPageSize',page_size);
                var send_data={
                    current_page:current_page,
                    page_size:page_size,
                    nickname:this.nickname,
                }
                let that=this;
                getStaffList(send_data).then(function(response){
                    if(response.data.code==1){
                      that.stafflist=response.data.list;
                      that.total_count=response.data.total_count;
                    }
                });
            },
            search(){
               this.getList(1,this.$store.getters.getCurrentPageSize);
            },
            add(){
               this.showDialog=true;
               this.searchStaff();
            },
            edit(id,enabled){
               let send_data={
                  id:id,
                  enabled:enabled
               };
               let that=this;
               setStaff(send_data).then(function(response){
                   let type=response.data.code==1?'success':'error';
                   that.$message({
                       message:response.data.msg,
                       type:type,
                       onClose:function(e){
                           that.reload();
                       }
                   });
               })
            },
            del(id){
                let that=this;
                this.$confirm('确认解除该理赔人员, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    let send_data={
                        id:id,
                        is_staff:0
                    };
                    setStaff(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        that.$message({
                            message:response.data.msg,
                            type:type,
                            onClose:function(e){
                                that.reload();
                            }
                        });
                    })
                })
            },
            //查询理赔人员
            searchStaff(){
                let send_data={
                    nickname:this.search_nickname
                }
                let that=this;
                listAllUser(send_data).then(function(response){
                    if(response.data.code==1){
                        that.alluserlist=response.data.list;
                    }
                })
            },
            closeDialog(){
               this.showDialog=false;
            },
            setStaff(id){
               let that=this;
               this.$confirm('确认将其设置为理赔人员, 是否继续?', '提示', {
                   confirmButtonText: '确定',
                   cancelButtonText: '取消',
                   type: 'warning'
               }).then((e) => {
                   let send_data={
                       id:id,
                       is_staff:1
                   };
                   setStaff(send_data).then(function(response){
                       let type=response.data.code==1?'success':'error';
                       that.$message({
                           message:response.data.msg,
                           type:type,
                           onClose:function(e){
                              that.reload();
                           }
                       });
                   })
               })
            }
        },
        created() {
            this.getList(1,this.$store.state.default_page_size);
        },
    }
</script>
<style>
  #staff-dialog .el-dialog__body{
     padding:15px 10px !important;
  }
</style>
